//
//  HCFindContentView.m
//  HappyChildren
//
//  Created by WillyZhao on 2016/12/29.
//  Copyright © 2016年 WillyZhao. All rights reserved.
//

#import "HCFindContentView.h"

#import "HCFindContentMoreView.h"

#import "HCFindModel.h"

#import "HCEveryDayModel.h"
#import "HCAllUsedModel.h"

@interface HCFindContentView () <HCFindHeaderViewDelegate,HCFindContentMoreViewClicked> {
    HCFindModel *model_;
    HCAllUsedModel *alluseModel;
    HCEveryDayModel *everyModel;
    HCFindContentMoreView *dayRecom;
    HCFindContentMoreView *allRecom;
    HCFindContentMoreView *hotRecom;
}

@end

@implementation HCFindContentView

-(instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        [self loadSubViews:frame];
    }
    return self;
}

-(void)loadSubViews:(CGRect)frame {
    self.contentScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height)];
    self.contentScrollView.backgroundColor = YBKRGBCOLOR(241, 241, 241, 1);
    self.contentScrollView.showsVerticalScrollIndicator = NO;
    [self addSubview:self.contentScrollView];
    
    self.header = [[HCFindHeaderView alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, YBKAdaptiveH(230))];
    self.header.delegate = self;
    [self.contentScrollView addSubview:self.header];
    
    //热推
    hotRecom = [[HCFindContentMoreView alloc] initWithFrame:CGRectMake(0, _header.frame.origin.y+_header.frame.size.height+58, frame.size.width, YBKAdaptiveH(310)) andStyle:HCFindContentMoreViewHotRecom];
    hotRecom.delegate = self;
    hotRecom.tag = 1;
    [self.contentScrollView addSubview:hotRecom];
    
    //每日特价
    dayRecom = [[HCFindContentMoreView alloc] initWithFrame:CGRectMake(0, hotRecom.frame.origin.y+hotRecom.frame.size.height+YBKAdaptiveH(10), hotRecom.frame.size.width, hotRecom.frame.size.height) andStyle:HCFindContentMoreViewDay];
    dayRecom.tag = 2;
    dayRecom.delegate = self;
    [self.contentScrollView addSubview:dayRecom];
    
    //大家都在用
    allRecom = [[HCFindContentMoreView alloc] initWithFrame:CGRectMake(0, dayRecom.frame.origin.y+dayRecom.frame.size.height+YBKAdaptiveH(10), hotRecom.frame.size.width, hotRecom.frame.size.height) andStyle:HCFindContentMoreViewAll];
    allRecom.delegate = self;
    allRecom.tag = 3;
    [self.contentScrollView addSubview:allRecom];
    
    self.contentScrollView.contentSize = CGSizeMake(frame.size.width, allRecom.frame.origin.y+allRecom.frame.size.height);
}

-(void)happyFindClicked:(HCFindHeaderButton *)btn {
    if ([self.delegate respondsToSelector:@selector(HCFindContentViewClicked:)]&&self.delegate) {
        [self.delegate HCFindContentViewClicked:btn];
    }
}

-(void)HCFindContentMoreViewClicked:(NSIndexPath *)indexPath view:(HCFindContentMoreView *)ve {
    if (ve.tag == 1) {
//        NSLog(@"热推");
        [self.delegate HCFindContentViewClickedContent:indexPath view:ve.tag];
    }else if (ve.tag == 2) {
//        NSLog(@"每日特价");
        [self.delegate HCFindContentViewClickedContent:indexPath view:ve.tag];
    }else if (ve.tag == 3) {
//        NSLog(@"大家都在用");
        [self.delegate HCFindContentViewClickedContent:indexPath view:ve.tag];
    }else{
        NSLog(@"无效");
    }
}

-(void)setModel:(id)model {
    if ([model isKindOfClass:[HCFindModel class]]) {
        model_ = (HCFindModel *)model;
        if (model_) {
            hotRecom.model = model_;
        }
    }

    if ([model isKindOfClass:[HCEveryDayModel class]]) {
        everyModel = (HCEveryDayModel *)model;
        if (everyModel) {
            dayRecom.model = everyModel;
        }
    }
    
    if ([model isKindOfClass:[HCAllUsedModel class]]) {
        alluseModel = (HCAllUsedModel *)model;
        if (alluseModel) {
            allRecom.model = alluseModel;
        }
    }
    
}

-(void)happyFindImageClicked:(NSInteger)index {
    if ([self.delegate respondsToSelector:@selector(HCFindImageClicked:)]) {
        [self.delegate HCFindImageClicked:index];
    }
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
